package grex;
/*
 * PersistenceGP.java
 *
 * Created on den 16 maj 2007, 21:56
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author rik
 */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
public class PersistenceGP {
    private static PersistenceGP instance;
    /** Creates a new instance of PersistenceGP */
    private PersistenceGP() {
    }
    
    public static PersistenceGP getInstance(){
        if(instance == null)
            instance = new PersistenceGP();
        return instance;
    }
    
    public void saveGP(GP gp,String file){
        ObjectOutputStream o;
        try{
            o = new ObjectOutputStream(new PrintStream(new File(file)));
            o.writeObject(gp);
            o.close();
        } catch (FileNotFoundException ex) {
            ErrorManager.getInstance().reportError(ex);
        } catch (IOException ex) {
            ErrorManager.getInstance().reportError(ex);
        }
        
    }
    
    public GP loadGP(String file){
        try {
            ObjectInputStream i = new ObjectInputStream(new FileInputStream(file));
            GP gp = (GP) i.readObject();
            return (GP) gp;
        } catch (FileNotFoundException ex) {
            ErrorManager.getInstance().reportError(ex);
        } catch (IOException ex) {
            ErrorManager.getInstance().reportError(ex);
        }catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        return null;
    }
    
    
}
